#include "skilltreeui.h"
#include <stdio.h>
#include <string.h>

// 递归打印二叉树（ASCII结构+彩色）
static void printTreeAsciiColor(BinTreeNode* node, const char* prefix, int isLeft, int isRoot) {
    if (!node) return;
    printf("%s", prefix);
    if (isLeft == -1) {
        // 根节点
        printf("\033[1;36m%s\033[0m\n", node->skill);
    } else if (isLeft) {
        printf("\033[1;34m├──\033[0m ");
        printf("\033[1;37m%s\033[0m\n", node->skill);
    } else {
        printf("\033[1;34m└──\033[0m ");
        printf("\033[1;37m%s\033[0m\n", node->skill);
    }

    char newPrefix[256];
    strcpy(newPrefix, prefix);
    if (isLeft == -1)
        strcat(newPrefix, "");
    else if (isLeft)
        strcat(newPrefix, "\033[1;34m│   \033[0m");
    else
        strcat(newPrefix, "    ");

    if (node->left && node->right) {
        printTreeAsciiColor(node->left, newPrefix, 1, 0);
        printTreeAsciiColor(node->right, newPrefix, 0, 0);
    } else if (node->left) {
        printTreeAsciiColor(node->left, newPrefix, 0, 0);
    } else if (node->right) {
        printTreeAsciiColor(node->right, newPrefix, 0, 0);
    }
}

void skilltreePrint(BinTreeNode* root) {
    printf("\n\033[1;34m╔══════ Skill Tree ══════╗\033[0m\n");
    printTreeAsciiColor(root, "", -1, 1);
    printf("\033[1;34m╚════════════════════════╝\033[0m\n");
}

void skilltreePrintStats(BinTreeNode* root) {
    printf("\033[1;37mTotal Skills: \033[0m\033[1;32m%d\033[0m\n", bintreeNodeCount(root));
    printf("\033[1;37mSkills Depth(Tree Depth): \033[0m\033[1;32m%d\033[0m\n", bintreeDepth(root));
    printf("\033[1;37mMost Powerful Skills(Leaf Skills): \033[0m\033[1;32m%d\033[0m\n", bintreeLeafCount(root));
} 